package com.jiantong.user.impl.service;

import com.google.common.base.Throwables;
import com.jiantong.user.impl.dao.GovernmentDao;
import com.jiantong.user.model.Government;
import com.jiantong.user.service.GovernmentReadService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by niufei on 2017/4/6.
 *
 */
@Slf4j
@Service
@RpcProvider
public class GovernmentReadServiceImpl implements GovernmentReadService {


    private final GovernmentDao governmentDao;
    @Autowired
    public GovernmentReadServiceImpl(GovernmentDao governmentDao) {
        this.governmentDao = governmentDao;
    }

    @Override
    public Response<List<Government>> selectList(Map criteria) {
        try {
            return Response.ok(governmentDao.list(criteria));
        } catch (Exception e) {
            log.error("failed to find government ", Throwables.getStackTraceAsString(e));
            return Response.fail("find.government.user.failed");
        }
    }

    @Override
    public Response<Government> findById(Long id) {
        try {
            return Response.ok(governmentDao.findById(id));
        } catch (Exception e) {
            log.error("failed to find government ", Throwables.getStackTraceAsString(e));
            return Response.fail("find.government.user.failed");
        }
    }
}
